package crx.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sound.midi.Soundbank;

import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;

import crx.dao.BaseDao;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@WebServlet("/InsertUserServlet")
public class InsertUserServlet extends BaseServlet {
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.request = request;
		this.response = response;
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setHeader("Content-Type", "text/html;charset=utf-8");
		if ("InsertUser".equals(request.getParameter("type"))) {
			String tel=getString("tel");
			String name=getString("name");
			String pwd=getString("pwd");
			Integer sex=getInt("sex");
			String job=getString("job");
			String cities1=getString("cities1");
			String cities2=getString("cities2");
			String cities3=getString("cities3");
			String cities=cities1+","+cities2+","+cities3;
			String introduction=getString("introduction");
			String sql="insert into user(usertel,username,userpwd,usersex,userjob,useraddress,userintroduction,a)  values(?,?,?,?,?,?,?,?)";
			try {
				Integer update = BaseDao.query.update(sql,tel,name,pwd,sex,job,cities,introduction);
				response.getWriter().write(gson.toJson(update));
				System.out.println(gson.toJson(update));
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}
}
